package com.pine.sunshineelder.waiter.web.handler;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.pine.sunshineelder.common.StringHelper;
import com.pine.sunshineelder.common.dto.JSONResponse;
import com.pine.sunshineelder.common.dto.QueryResult;
import com.pine.sunshineelder.waiter.ao.ElderDoctorAo;
import com.pine.sunshineelder.waiter.service.ElderDoctorService;
import com.pine.sunshineelder.waiter.vo.ElderDoctorVo;

@RestController
@RequestMapping("/api/elderdoctor")
public class ElderDoctorHandler implements StringHelper{
	@Autowired
	ElderDoctorService service;
	
	@PostMapping("/add")
	public JSONResponse registerElderBed(ElderDoctorAo ao) throws Exception {
		ElderDoctorVo elderAide = service.addElderDoctor(ao);

		return JSONResponse.ok(elderAide);
	}
	
	@GetMapping("/{id}")
	public JSONResponse selectByElderDoctorId(@PathVariable("id") String id) throws Exception {
		ElderDoctorVo elderDoctorId = service.selectById(id);
		return JSONResponse.ok(elderDoctorId);
	}
	
	@DeleteMapping("/del/{id}")
	public JSONResponse deleteElderDoctor(@PathVariable("id") String id) throws Exception{
		service.deleteElderDoctorById(id);
		return JSONResponse.ok();
	}
	
	@GetMapping("/list")
	public JSONResponse listElderDoctor(String key, String pageNo, String pageSize) throws Exception {
		System.out.println("--------->");
		Integer pageNoUse = parseInt(pageNo, null);
		Integer pageSizeUse = parseInt(pageSize, null);
		QueryResult result = service.queryByKey(key, pageNoUse, pageSizeUse);
		return JSONResponse.ok(result);
	}
	
}
